
import request from './request.js'
// import store from '@/store'

/**
 * @desc 描述用户登录
 * @param { username:String,password:String } user 
 * @returns 登录消息
 * @author chw
 * @date 2022年7月14日11:09:21
 */
const userLogin = function(user={}){
    return request.post("/login",user,{
        isPublic:true // 自定义配置 = 表示该请求不需要授权
    })
}
const getUserList = function(params={}){
    return request.get("/users",{
        params:params
    })
}
const deleteUser = function(id=""){
    return request.delete(`/users/${id}`);
}
const updateUserSateById = function(id="",state=false){
    return request.put(`/users/${id}/state/${state}`)
}

const getLeftMenu = function(){
    return request.get("/menus",{
        // headers:{
        //     Authorization:store.state.token
        // }
    })
} 

const getCategories = function(params={}){
    return request.get("/categories",{
        params
    })
}

const getRolesList = function(){
    return request.get("/roles")
}
const updateRoleRights = function(roleId="",params={}){
    return request.post(`roles/${roleId}/rights`,params)
}

const getRightsList = function(type="list"){
    return request.get(`/rights/${type}`)
}

const getReport = function(type=1){
    return request.get(`reports/type/${type}`)
}

const api = {
    userLogin,getUserList,deleteUser,updateUserSateById,
    getLeftMenu,
    getRolesList,updateRoleRights,
    getRightsList,
    getCategories,
    getReport
}
export default {
    ...api,
    install(Vue){
        Vue.prototype.$api = api
    }
}